<?php

namespace App\Console\Commands;
use App\Models\Circle;
use App\Models\City;
use App\Models\UserJoinCircle;
use Illuminate\Console\Command;

class CityCircleCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'city-circle';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
//        Circle::where('is_area', 1)->chunk(50, function ($list) {
//            foreach ($list as $item) {
//                UserJoinCircle::firstOrCreate([
//                    'user_id' => 1,
//                    'circle_id' => $item->id,
//                    'is_owner' => 1
//                ]);
//            }
//        });
//
//        return;
        City::chunk(50, function ($list) {
            foreach ($list as $city) {
                $circle1 = Circle::create([
                    'user_id' => 1,
                    'is_area' => 1,
                    'title' => $city->name . '猫咪宠物圈',
                    'desc' => '欢迎关注并分享给同城朋友，在这里一起交流分享养宠乐趣，不定期组织线下活动',
                    'city' => $city->name,
                    'city_code' => $city->code,
                    'status' => Circle::STATUS_SUCCESS,
                ]);
                UserJoinCircle::create([
                    'user_id' => 1,
                    'circle_id' => $circle1->id,
                    'is_owner' => 1
                ]);
                $circle2 = Circle::create([
                    'user_id' => 1,
                    'is_area' => 1,
                    'title' => $city->name . '狗狗宠物圈',
                    'desc' => '欢迎关注并分享给同城朋友，在这里一起交流分享养宠乐趣，不定期组织线下活动',
                    'city' => $city->name,
                    'city_code' => $city->code,
                    'status' => Circle::STATUS_SUCCESS,
                ]);
                UserJoinCircle::create([
                    'user_id' => 1,
                    'circle_id' => $circle2->id,
                    'is_owner' => 1
                ]);
            }
        });

    }
}
